//
//  KDTitleMenuController.m
//  PublicSentimentMonitorSystem
//
//  Created by 魏强 on 15/11/24.
//  Copyright © 2015年 魏强. All rights reserved.
//

#import "KDTitleMenuController.h"
#import "KDAddWebsiteResultModel.h"
#import "KDWebResultCell.h"
@interface KDTitleMenuController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, weak) UIButton *confirmBtn;
@property (nonatomic, weak) UITableView *tableView;

@end

@implementation KDTitleMenuController

- (void)viewDidLoad {
    self.view.backgroundColor = [UIColor whiteColor];
    [super viewDidLoad];
    
}
- (void)setNewSize:(CGSize)newSize{
    [self setUpTableView];
    [self setUpConfirmBtn];
}
- (void)setUpTableView{
    UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0  ,0, self.view.width ,  200 - 30 - 44 ) style:UITableViewStylePlain];
    if (self.info.count <= 5) {
        tableView.height = 40 * self.info.count;
    }else{
        tableView.height = 200;
    }
    self.tableView = tableView;
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.tag = 1000;
    tableView.tableFooterView = [UIView new];
    tableView.separatorColor = BackGroundColor;
    tableView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:tableView];
}
- (void)setUpConfirmBtn{
    UIButton *confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    confirmBtn.frame = CGRectMake((self.view.width - 120) *0.5, CGRectGetMaxY(self.tableView.frame) +30, 120, 30);
    
    [confirmBtn setTitle:@"确定" forState:UIControlStateNormal];
    [confirmBtn addTarget:self action:@selector(confirmBtnClick) forControlEvents:UIControlEventTouchUpInside];
    confirmBtn.layer.cornerRadius = 5.0;
    confirmBtn.clipsToBounds = YES;
    confirmBtn.backgroundColor = KDHeadColor;
    [confirmBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];;
    self.confirmBtn = confirmBtn;
    [self.view addSubview:confirmBtn];
}
#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.info.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    KDWebResultCell *cell = [KDWebResultCell cellWithTableView:tableView];
    KDAddWebsiteResultModel *model = self.info[indexPath.row];
    cell.model = model;
    
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (_delegate &&[_delegate respondsToSelector:@selector(tableViewCellDidSelectWithRow:)]) {
        [_delegate tableViewCellDidSelectWithRow:indexPath.row];
    }
}
- (void)confirmBtnClick{
    if (_delegate &&[_delegate respondsToSelector:@selector(confirmBtnClick)]) {
        [_delegate confirmBtnClick];
    }
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
